-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
promises: use encoding in readFile #19296
Conversation
Random question - do I label this |
async function doReadWithEncoding() { | ||
const data = await fsPromises.readFile(dest, 'utf-8'); | ||
const buf = fs.readFileSync(dest, 'utf-8'); | ||
assert.deepStrictEqual(buf, data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we assert the type of data
and buf
as well, here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, good idea
Use the encoding parameter passed to fsPromises.readFile if it is passed. Currently the encoding parameter is ignored in fsPromises PR-URL: nodejs#19296 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Fixes: nodejs#19286
ef7b77d
to
6469a62
Compare
|
CI looks green sans an unrelated http2 failure: https://ci.nodejs.org/job/node-test-commit/16860// |
lib/fs/promises.js
Outdated
@@ -157,7 +157,12 @@ async function readFileHandle(filehandle, options) { | |||
chunks.push(buffer.slice(0, totalRead)); | |||
} while (totalRead === chunkSize); | |||
|
|||
return Buffer.concat(chunks); | |||
var buffer = Buffer.concat(chunks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/var/const
I think |
Landed in e06ad5f. |
Use the encoding parameter passed to fsPromises.readFile if it is passed. Currently the encoding parameter is ignored in fsPromises. PR-URL: #19296 Fixes: #19286 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
const data = await fsPromises.readFile(dest, 'utf-8'); | ||
const syncData = fs.readFileSync(dest, 'utf-8'); | ||
assert.strictEqual(typeof data, 'string'); | ||
assert.deepStrictEqual(data, syncData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.strictEqual()
was probably better here, but I've already landed this and it's not a biggie so I will not force push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lpinca why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a string no? No need to be deep.
Fixes: #19286
@nodejs/fs